package com.spring.springboot.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


/**
 * 项目名称: java_algorithm
 * @ClassName MyApplicationContextAware
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2022/5/20 9:09
 */
@Component
public class MyApplicationContextAware implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        MyApplicationContextAware.applicationContext=applicationContext;
    }

    public static Object getBean(Class clazz){
        Object bean = applicationContext.getBean(clazz);
        return bean;
    }
}
